/**
 * This file is part of XaMauLo 
 * File :                       SchemaXML.scala
 * Author's email :             laure.conte@gmail.com
 *                              sophie.couillez@gmail.com
 **/

package main;
import utils._;
import scala.xml._;
import org.xml.sax._;
import scala.xml.include.sax._;
import org.xml.sax.helpers.XMLReaderFactory;


/**
  *This object contains the main. It executes the program
 */

object Xamaulo {

val docX : DocumentXML=new DocumentXML;

  //Try if the command is correct
  def executeCommand(choix :List[String]) = choix.size match{
    case 2 if choix.head.equals("-verify")=> docX.verifyXML(choix.last);
    case 3 if choix.head.equals("-validate")=> var tmp=choix.tail;docX.readXML(tmp.head,tmp.last);
    case 5 if(choix.contains("-out"))=>docX.fichierResult=choix.last;var tmp=choix.tail;var tmpXML=tmp.head;tmp=tmp.tail;docX.readXML(tmpXML,tmp.head);
    case _ => println("Error XaMauLo need 1, 2 or 3 arguments!");
  }
  
  //Try if the number of Arguments is correct
  def verifArgs(choix : Array[String]): boolean = choix match{
  case null => println("Error XaMauLo need one or more arguments! ");return false;
  case _ => choixMenu(choix.toList); 
}
  
  //Try if the command is null
  def choixMenu(choix : List[String]): boolean = choix match{
    case List() => println("Please enter a correct command"); return false;
    case _ => if (choix.contains("-help")){docX.showManPage()}else executeCommand(choix);return true;
  }
  
  //Main
  def main(args: Array[String]) {
   println(args.toString);
   println("Xamaulo\n\n");
   println("Enter -help to see the man page");
   verifArgs(args); 

  }
}
